<?php 
 define('PRODUCTS',22);
 define('COLS', 5);
 $count = 0;
 $rows = ceil( PRODUCTS / COLS )  ;
 $table =  "<table width='50%' 
 align='center'>";
 for($i=1 ; $i<=$rows ; $i++) {
   $color = ($i%2==0)?'red':'green';
   $table .= "<tr>";
   for($j=1 ; $j<=COLS ;$j++) {
   	$count++;
   	if($count<=PRODUCTS) {
     $table .="<td style='background:$color'>
     {$count}</td>";	
	} else {
     $table .= "<td style='background:$color'>
     &nbsp;</td>";	 		
	}
   }
   $table .="</tr>";
 }
 $table .="</table>";
 

 echo $table;